/*
 * @Author: wangzhongjie
 * @Date: 2020-02-24 10:43:35
 * @LastEditors: wangzhongjie
 * @LastEditTime: 2020-02-27 14:09:59
 * @Description:wangzhongjie
 * @Email: UvDream@163.com
 */

package other

import (
	"go-gin-api/app/util"

	"github.com/gin-gonic/gin"
)

// UploadImagesService 上传图片服务
func UploadImagesService(c *gin.Context) *util.Response {
	// 单文件
	file, _ := c.FormFile("file")
	// 上传文件到指定的路径
	dst := "/www/admin/api/images/" + file.Filename
	err := c.SaveUploadedFile(file, dst)
	if err != nil {
		return &util.Response{
			Code:    40004,
			Message: "failed",
			Data:    "上传失败!",
		}
	}
	imgURL := "/images/" + file.Filename
	return &util.Response{
		Code:    200,
		Message: "success",
		Data:    imgURL,
	}
}
